package com.sdgakj.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name="f_msg_user")
public class MessageUser extends IdEntity {
	
	private Date createdate;
	private Date updatedate;
	private String deltag="0";
	private String isread;
	private Long userId;
	private Message message;
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreatedate() {
		return createdate;
	}
	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}
	@JsonIgnore
	public String getDeltag() {
		return deltag;
	}
	public void setDeltag(String deltag) {
		this.deltag = deltag;
	}
	public String getIsread() {
		return isread;
	}
	public void setIsread(String isread) {
		this.isread = isread;
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getUpdatedate() {
		return updatedate;
	}
	public void setUpdatedate(Date updatedate) {
		this.updatedate = updatedate;
	}
	
	@ManyToOne
	@JoinColumn(name="mid")
	@JsonIgnore
	public Message getMessage() {
		return message;
	}
	public void setMessage(Message Message) {
		this.message = message;
	}
	@Transient
	public Long getMesId() {
		if(message!=null){
			return message.getId();
		}
		return 0l;
	}

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    @Transient
	public String getMsg() {
		if(message!=null){
			return message.getMsg();
		}
		return "";
	}
	
	@Transient
	public String getMsgMode() {
		if(message!=null){
			return message.getMode();
		}
		return "";
	}
	
	@Transient
	public String getMsgModeStr() {
		if(message!=null){
			String mode =  message.getMode();
			if(StringUtils.isNotBlank(mode)){
				 if(mode.equals("2")){
					return "温馨提示";
				}else{
					return "普通消息";
				}
			}
		}
		return "";
	}
	
	@Transient
	public String getMsgTitle() {
		if(message!=null){
			return  message.getTitle();
		}
		return "";
	}

    @Transient
	public String getMsgLink() {
		if(message!=null){
			return  message.getLink();
		}
		return "";
	}
}
